// base
import Taro, { Component } from '@tarojs/taro'
import { View, Image, Form, Button } from '@tarojs/components'
import { connect } from '@tarojs/redux'
// less
import './index.less'
import pagejumplist from '../../../configuration/pagejumplist.json'
import { navigateTo } from '../../../crossplatform/apiservice/navigate'
import { UPDATEPAGEPERSONDETAIL } from '../../../pages/person-detail/store/types/pagepersondetail'
import AlumniListItem from '../alumni-list-item'

@connect(
  userinfo => ({ ...userinfo }),
  dispatch => ({
    updatePersonDetail(payload) {
      dispatch({
        type: UPDATEPAGEPERSONDETAIL,
        payload: {
          ...payload
        }
      })
    }
  })
)
class AlumniMessageList extends Component {
  static defaultProps = {
    dataSource: []
  }

  constructor(props) {
    super(props)
    this.state = {}
  }

  componentWillMount() {
    // onLoad
  }

  goto = index => {
    const { dataSource = [], type } = this.props
    const dataSingle = dataSource[index]
    if (dataSingle.archive_state == 1 || type != 'collection') {
      this.props.updatePersonDetail({
        personDetail: dataSingle
      })
      navigateTo({
        url: `${pagejumplist['person-detail'].path}?userId=${dataSingle.id}`
      })
    }
  }

  render() {
    const { dataSource = [], type } = this.props

    return (
      <View className="AlumniMessageList_id21850">
        {dataSource.map((data, index) => {
          return <AlumniListItem type={type} data={data} onTap={this.goto.bind(this, index)} />
        })}
      </View>
    )
  }
}

export default AlumniMessageList
